#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int N = 1e5 + 10, M = 2e6 + 10;
int n, m;
int h[N];
LL ret, cnt;
vector<PII> edges[N];
struct node
{
	int x, y, z;
}e[M];
int fa[N];
bool st[N];
int pos;
int find(int x)
{
	return x == fa[x] ? x : fa[x] = find(fa[x]);
}
void dfs(int u)
{
	cnt++;
	st[u] = true;
	for (auto& t : edges[u])
	{
		int x = t.first, y = t.second;
		pos++;
		e[pos].x = u, e[pos].y = x, e[pos].z = y;

		if (!st[x]) dfs(x);
	}
}
bool cmp(node& a, node& b)
{
	int y1 = a.y, z1 = a.z, y2 = b.y, z2 = b.z;
	if (h[y1] == h[y2]) return z1 < z2;
	else return h[y1] > h[y2];
}
void kk()
{
	for (int i = 1; i <= n; i++) fa[i] = i;
	sort(e + 1, e + 1 + pos, cmp);
	for (int i = 1; i <= pos; i++)
	{
		int x = e[i].x, y = e[i].y, z = e[i].z;
		int fx = find(x), fy = find(y);
		if (fx != fy)
		{
			ret += z;
			fa[fx] = fy;
		}
	}
}
int main()
{
	cin >> n >> m;
	for (int i = 1; i <= n; i++) cin >> h[i];
	for (int i = 1; i <= m; i++)
	{
		int x, y, z; cin >> x >> y >> z;
		if (h[x] >= h[y]) edges[x].push_back({ y,z });
		if (h[y] >= h[x]) edges[y].push_back({ x,z });
	}
	dfs(1);
	
	cout << cnt << " ";
	kk();
	
	cout << ret << endl;
	return 0;
}